﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace MasApp.BLL
{
    public class Check
    {
        public Check()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }
        public static bool CheckLogin(string rolename)
        {
            if (HttpContext.Current.Session["userid"] != null)
            {
                string s = "SELECT     userrole.userroleid"
                    + " FROM         role INNER JOIN"
                    + " userrole ON role.roleid = userrole.roleid"
                    + " WHERE     (role.rolename = '" + rolename + "') AND (userrole.userid = " 
                    + HttpContext.Current.Session["userid"] + ")";
                return Convert.ToInt32(DAL.Search.ExecuteScalar(s)) > 0 ? true : false;
            }
            else
            {
                HttpContext.Current.Response.Redirect("~/public/welcome.aspx");
            }
            return false;
        }
        /// <summary>
        /// 
        /// </summary>
        public static void CheckLogin()
        {
            if (HttpContext.Current.Session["userid"] == null)
            {
                HttpContext.Current.Response.Redirect("~/public/welcome.aspx");
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public static bool CheckLoginForWelcome()
        {
            if (HttpContext.Current.Session["username"] == null)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool CheckPassword(string username, string password)
        {
            return MasApp.DAL.Check.CheckPassword(username, password);
        }
    }
}